package com.wei.czz.framework.blog.service.impl;

import com.wei.czz.common.enums.CommonEnum;
import com.wei.czz.common.utils.SecurityUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wei.czz.framework.blog.dao.BlogFlowDao;
import com.wei.czz.framework.blog.entity.BlogFlowEntity;
import com.wei.czz.framework.blog.service.BlogFlowService;

import java.util.Date;
import java.util.Objects;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2024-12-05 08:21:38
 * className: BlogFlowServiceImpl
 * version: 1.0
 * description:
 */
@Service("blogFlowService")
public class BlogFlowServiceImpl extends ServiceImpl<BlogFlowDao, BlogFlowEntity> implements BlogFlowService {

    private static final Logger log = LoggerFactory.getLogger(BlogFlowServiceImpl.class);

    @Override
    public void saveOrEdit(BlogFlowEntity blogFlow) {
        // 获取操作用户
        String username = SecurityUtils.getOrDefaultUsername(StringUtils.EMPTY);
        Long userId = SecurityUtils.getOrDefaultUserId(CommonEnum.ZERO.getLongValue());
        Date date = new Date();

        if (Objects.isNull(blogFlow.getId())) {
            blogFlow.setDeleteStatus(CommonEnum.ZERO.getValue())
                    .setCreateTime(date)
                    .setCreateUser(username)
                    .setCreateUserId(userId);

            int count = baseMapper.insert(blogFlow);
            log.info("保存博客流水完成。count={}", count);
        } else {
            int count = baseMapper.updateById(blogFlow);
            log.info("修改博客流水完成。count={}", count);
        }
    }
}